import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;

public class PixelChanger {
	
	String IN;
	String OUT;
	int[] KEYS;

	public PixelChanger(String path_in, String path_out, int[] keys) {
		this.IN = path_in;
		this.OUT = path_out;
		this.KEYS = keys;
	}

	public void encrypt() {
		try {
			BufferedImage in = ImageIO.read(new File(IN));
			BufferedImage out = new BufferedImage(in.getWidth(),
					in.getHeight(), BufferedImage.TYPE_INT_ARGB);

			for (int x = 0; x < in.getWidth(); x++) {
				for (int y = 0; y < in.getHeight(); y++) {
					out.setRGB(x, y, in.getRGB(x, y)
							^ KEYS[(x * y) % KEYS.length]);
				}
			}

			ImageIO.write(out, OUT.substring(OUT.length() - 3, OUT.length()),
					new File(OUT));
		} catch (IOException e) {
		}
	}
	
	public void decrypt() {
		encrypt();
	}

}
